package test.list;

public class Solution3 {

    public ListNode rotateRight(ListNode head, int k) {
        // 在此处写入代码
        ListNode next = head;
        ListNode newHead = head;
        while(next.next != null) {
            next = next.next;
        }
        next.next = head;
        for (; k >1; k--) {
            newHead = next.next;
        }
        ListNode newTail = newHead;
        newHead = newHead.next;
        newTail.next = null;
        return newHead;
    }

    class ListNode {
        int val;
        ListNode next;
        ListNode(int x) {
            val = x;
            next = null;
        }
    }
}
